/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package de.gbeine.java.depview.beans.converter;

import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.gbeine.java.depview.model.Package;

/**
 *
 * @author gbeine
 */
public class PackageFactory {

    private static final Logger LOGGER = LoggerFactory.getLogger(PackageFactory.class);
    private static final Map<String,Package> PACKAGES = new HashMap<String,Package>();

    public static Package createPackage(final String name) {
        Package pe;
        if (PackageFactory.PACKAGES.containsKey(name)) {
            if (PackageFactory.LOGGER.isDebugEnabled()) {
                PackageFactory.LOGGER.debug("Package " + name + " already exists.");
            }
            pe = PackageFactory.PACKAGES.get(name);
        } else {
            if (PackageFactory.LOGGER.isDebugEnabled()) {
                PackageFactory.LOGGER.debug("Creating new Package: " + name);
            }
            pe = new Package(name);
            PackageFactory.PACKAGES.put(name, pe);
        }
        return pe;
    }
}
